cssparser: Make _gtk_css_parser_has_number() a bit smarter
authorBenjamin Otte <otte@redhat.com>
Tue, 23 Feb 2016 03:19:42 +0000 (04:19 +0100)
committerBenjamin Otte <otte@redhat.com>
Tue, 23 Feb 2016 03:22:19 +0000 (04:22 +0100)
Previously we just checked the first character. And if that was a "-" as
in "-gtk-some-special-value", we assumed it was a number. Which it
clearly wasn't.

Test included

gtk/gtkcssparser.c
testsuite/css/parser/Makefile.am
testsuite/css/parser/background-win32-color-is-no-error.css [new file with mode: 0644]
testsuite/css/parser/background-win32-color-is-no-error.ref.css [new file with mode: 0644]

index 86320f3a729ebed99ae8d695f7c51a1da1d49997..44ff7bcfca738427c5422932559324d6d77373eb 100644 (file)
@@ -599,8 +599,15 @@ _gtk_css_parser_try_double (GtkCssParser *parser,
 gboolean
 _gtk_css_parser_has_number (GtkCssParser *parser)
 {
+  char c;
+
+  if (parser->data[0] == '-' || parser->data[0] == '+')
+    c = parser->data[1];
+  else
+    c = parser->data[0];
+
   /* ahem */
-  return strchr ("+-0123456789.", parser->data[0]) != NULL;
+  return g_ascii_isdigit (c) || c == '.';
 }
 
 GtkCssValue *
index 54c9506a5fc17642156deb1c1ab077ee465442db..d7744764ccccff6a5ba5e06d7f1a9ae7af832929 100644 (file)
@@ -195,6 +195,8 @@ test_data = \
        background-shorthand-single.ref.css \
         background-size.css \
         background-size.ref.css \
+       background-win32-color-is-no-error.css \
+       background-win32-color-is-no-error.ref.css \
        border.css \
        border.errors \
        border.ref.css \
diff --git a/testsuite/css/parser/background-win32-color-is-no-error.css b/testsuite/css/parser/background-win32-color-is-no-error.css
new file mode 100644 (file)
index 0000000..3b17e20
--- /dev/null
@@ -0,0 +1,3 @@
+a {
+  background: -gtk-win32-color(edit, highlight);
+}
diff --git a/testsuite/css/parser/background-win32-color-is-no-error.ref.css b/testsuite/css/parser/background-win32-color-is-no-error.ref.css
new file mode 100644 (file)
index 0000000..7879519
--- /dev/null
@@ -0,0 +1,9 @@
+a {
+  background-clip: border-box;
+  background-color: -gtk-win32-color(edit, highlight);
+  background-image: none;
+  background-origin: padding-box;
+  background-position: left top;
+  background-repeat: repeat;
+  background-size: auto;
+}